<?php


namespace App\Web\Controller;

use App\Web\Facades\UserAuth;
use App\Web\Model\Interview as InterviewModel;
use EchoPHP\Http\Request;

class Interview extends Controller {

    public function add(Request $request) {
        $oprInfo = UserAuth::getLoginInfo();
        $subId = $request->getPost('subid/d', 0);
        $caseResumeIds = $request->getPost('caseresumeids', '');
        $interviewType = $request->getPost('interviewtype/d', 1);
        $templateType = $request->getPost('templatetype', 1);
        $sendDate = $request->getPost('senddate', '');
        $projectId = $request->getPost('projectid', 0);
        $interviewParams = [
            'jobname' => $request->getPost('jobname', ''),
            'jobcompany' => $request->getPost('jobcompany', ''),
            'interviewtime' => $request->getPost('interviewtime', ''),
            'address' => $request->getPost('address', ''),
            'contract' => $request->getPost('contract', ''),
            'mobilephone' => $request->getPost('mobilephone', ''),
            'memo' =>$request->getPost('memo', ''),
        ];
        $interviewModel = new InterviewModel();
        $result = $interviewModel->addInterviewNotice($oprInfo, $subId, $projectId ,$caseResumeIds, $interviewParams, $sendDate, $interviewType, $templateType);
        return $this->json($result);
    }
    /***
     * 查询面试通知
     */
    public function sel(Request $request){
        $oprId = $this->getLoginId();
        $pageNum = $request->getParam('pagenum/d', 1);
        $pageLimit = $request->getParam('pagelimit/d', 10);
        $search = [
            'sendtype' => $request->getParam('sendtype'),
            'templatetype' => $request->getParam('templatetype'),
        ];
        $interviewModel = new InterviewModel();
        list($pageNum, $rowFrom, $rowTo) = $interviewModel->paginationParameters($pageNum, $pageLimit);
        $count = $interviewModel->getCount($oprId, $search);
        if (0 == $count) {
            return $this->json(['status' => true, 'message' => '获取成功', 'totalcount' => 0, 'interviewlist' => []]);
        }
        $interviewlist = $interviewModel->selInterview($oprId, $search, '', $rowFrom, $rowTo);
        return $this->json(['status' => true, 'message' => '获取成功', 'totalcount' => $count, 'interviewlist' => $interviewlist]);
    }

}